package com.blb.service.user.impl;

import com.blb.dao.user.impl.DeliverAddressDaoImpl;
import com.blb.pojo.UserAddress;
import com.blb.service.user.IDeliverAddressService;
import com.blb.utils.ApplicationContextUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.sql.SQLException;
import java.util.List;

@Service
public class DeliverAddressServiceImpl implements IDeliverAddressService {

    @Autowired
    private DeliverAddressDaoImpl deliverAddressDao;

    @Override
    public List<UserAddress> getUserAddress() throws Exception {
        return deliverAddressDao.selectUserAddress();
    }

    @Override
    public void reviseDefault(int id) throws SQLException, ClassNotFoundException {
        deliverAddressDao.updateDefault(id);
    }

    @Override
    public void addAddress(UserAddress address) throws SQLException, ClassNotFoundException {
        deliverAddressDao.insertAddress(address);
    }

    @Override
    public UserAddress getAddressById(String id) throws Exception {
        List<UserAddress> list = deliverAddressDao.updateAddressById(id);
        return list.get(0);
    }
}
